<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>使用键名比较计算数组的差集</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-diff-assoc.html">array_diff_assoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-diff-uassoc.html">array_diff_uassoc</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-diff-key" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_diff_key</h1>
    <p class="verinfo">(PHP 5 &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">array_diff_key</span> &mdash; <span class="dc-title">使用键名比较计算数组的差集</span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.array-diff-key-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>array_diff_key</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array1</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$array2</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$...</code></span>
  ] )</div>

    <p class="para rdfs-comment">
     根据 <em><code class="parameter">array1</code></em> 中的键名和 <em><code class="parameter">array2</code></em> 进行比较，返回不同键名的项。
     本函数和
     <span class="function"><a href="function.array-diff.html" class="function">array_diff()</a></span> 相同只除了比较是根据键名而不是值来进行的。
    </p>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.array-diff-key-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>


    
     <dt>
<em><code class="parameter">array1</code></em></dt>

     <dd>

      <p class="para">
       从这个数组进行比较
      </p>
     </dd>

    

    
     <dt>
<em><code class="parameter">array2</code></em></dt>

     <dd>

      <p class="para">
       针对此数组进行比较
      </p>
     </dd>

    

    
     <dt>
<em><code class="parameter">...</code></em></dt>

     <dd>

      <p class="para">
       更多比较数组
      </p>
     </dd>

    

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-diff-key-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>array_diff_key()</strong></span> 返回一个数组，该数组包括了所有出现在
     <em><code class="parameter">array1</code></em>
     中但是未出现在任何其它参数数组中的键名的值。
  </p>
 </div>




 <div class="refsect1 examples" id="refsect1-function.array-diff-key-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4840">
    <p><strong>Example #1 <span class="function"><strong>array_diff_key()</strong></span> 例</strong></p>
    <div class="example-contents"><p>
      在 <em>key =&gt; value</em> 对中的两个键名仅在
     <em>(string) $key1 === (string) $key2 </em>
     时被认为相等。换句话说，执行的是严格类型检查，因此字符串的表达必须完全一样。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$array1&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'blue'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'red'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'green'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'purple'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$array2&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'green'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'blue'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'yellow'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'cyan'&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">array_diff_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$array1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(2) {
  [&quot;red&quot;]=&gt;
  int(2)
  [&quot;purple&quot;]=&gt;
  int(4)
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.array-diff-key-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
      注意本函数只检查了多维数组中的一维。当然，可以用
      <em>array_diff_key($array1[0], $array2[0]);</em>
      来检查更深的维度。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-diff-key-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.array-diff.html" class="function" rel="rdfs-seeAlso">array_diff()</a> - 计算数组的差集</span></li>
    <li class="member"><span class="function"><a href="function.array-udiff.html" class="function" rel="rdfs-seeAlso">array_udiff()</a> - 用回调函数比较数据来计算数组的差集</span></li>
    <li class="member"><span class="function"><a href="function.array-diff-assoc.html" class="function" rel="rdfs-seeAlso">array_diff_assoc()</a> - 带索引检查计算数组的差集</span></li>
    <li class="member"><span class="function"><a href="function.array-diff-uassoc.html" class="function" rel="rdfs-seeAlso">array_diff_uassoc()</a> - 用用户提供的回调函数做索引检查来计算数组的差集</span></li>
    <li class="member"><span class="function"><a href="function.array-udiff-assoc.html" class="function" rel="rdfs-seeAlso">array_udiff_assoc()</a> - 带索引检查计算数组的差集，用回调函数比较数据</span></li>
    <li class="member"><span class="function"><a href="function.array-udiff-uassoc.html" class="function" rel="rdfs-seeAlso">array_udiff_uassoc()</a> - 带索引检查计算数组的差集，用回调函数比较数据和索引</span></li>
    <li class="member"><span class="function"><a href="function.array-diff-ukey.html" class="function" rel="rdfs-seeAlso">array_diff_ukey()</a> - 用回调函数对键名比较计算数组的差集</span></li>
    <li class="member"><span class="function"><a href="function.array-intersect.html" class="function" rel="rdfs-seeAlso">array_intersect()</a> - 计算数组的交集</span></li>
    <li class="member"><span class="function"><a href="function.array-intersect-assoc.html" class="function" rel="rdfs-seeAlso">array_intersect_assoc()</a> - 带索引检查计算数组的交集</span></li>
    <li class="member"><span class="function"><a href="function.array-intersect-uassoc.html" class="function" rel="rdfs-seeAlso">array_intersect_uassoc()</a> - 带索引检查计算数组的交集，用回调函数比较索引</span></li>
    <li class="member"><span class="function"><a href="function.array-intersect-key.html" class="function" rel="rdfs-seeAlso">array_intersect_key()</a> - 使用键名比较计算数组的交集</span></li>
    <li class="member"><span class="function"><a href="function.array-intersect-ukey.html" class="function" rel="rdfs-seeAlso">array_intersect_ukey()</a> - 用回调函数比较键名来计算数组的交集</span></li>
   </ul>
  </p>
 </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.array-diff-assoc.html">array_diff_assoc</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.array-diff-uassoc.html">array_diff_uassoc</a></div>
 <div class="up"><a href="ref.array.html">数组 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
